package org.example;

import java.util.Stack;

//leetcode 232 用栈模拟队列 https://leetcode.cn/problems/implement-queue-using-stacks/description/
class MyQueue {
    Stack<Integer> stack1;
    Stack<Integer> stack2;
    public MyQueue() {
        stack1 = new Stack<>();
        stack2 = new Stack<>();
    }

    public void push(int x) {
        stack1.add(x);
    }

    public int pop() {
        int ret = -1;
        if (!stack1.empty()) {
            while (!stack1.empty()) {
                stack2.add(stack1.pop());
            }
            ret = stack2.pop();
            while (!stack2.empty()) {
                stack1.add(stack2.pop());
            }
        }
        return ret;
    }

    public int peek() {
        int ret = -1;
        if (!stack1.empty()) {
            while (!stack1.empty()) {
                stack2.add(stack1.pop());
            }
            ret = stack2.peek();
            while (!stack2.empty()) {
                stack1.add(stack2.pop());
            }
        }
        return ret;
    }

    public boolean empty() {
        return stack1.empty();
    }
}

public class Test1 {
}
